from race.Player import *
import logging.config
from threading import Thread

logging.config.fileConfig('./util/logging.conf')
log = logging.getLogger("example")


class DhTank(Player):
    def a(self):

        self.startScheduler1()  # 调用 CallBackScheduler1
        self.startScheduler2()  # 调用 CallBackScheduler2
        self.startScheduler4()  # 调用 CallBackScheduler4
        self.startScheduler3()  # 调用 CallBackScheduler3

        self.startTiggerHP100_90()
        self.startTiggerHP90_80()
        self.startTiggerHP80_70()
        self.startTiggerHP70_60()
        self.startTiggerHP60_50()
        self.startTiggerHP50_40()
        self.startTiggerHP40_30()
        return

    def CallBackHP100_90(self):
        while self.ui.stopLoop == False:
            # 幽魂炸弹
            self.click(self.kb, '6', 6)
            sleep(0.1)
            # 献祭光环
            self.click(self.kb, '4', 4)
            sleep(0.1)
            pass
    def CallBackHP90_80(self):
        while self.ui.stopLoop == False:

            # 尖刺减伤(血条低于多少，必然触发)(避免尖刺多开)
            # self.pubAvgColorTiggerKeyBloodBarMode(546, self.WABloodBarY, self.WABloodBarDeltaX, self.WABloodBarDeltaY,
            #                                       self.WABloodBarAvgColor, self.GREEN, 'small', '8', 0.06, 2,self.ELSEKEY_1, self.DEBUG_CLOSE)
            self.pubAvgColorTiggerKeyAndStopClickTwice(self.WABloodBarX + self.WABloodBarWidth * 0.85, self.WABloodBarY,
                                                       self.WABloodBarDeltaX,
                                                       self.WABloodBarDeltaY, self.WABloodBarAvgColor, self.GREEN,
                                                       'small',
                                                       '8', 0.06, 2, self.WA_SQUARE_ZFX_X2, self.WA_SQUARE_ZFX,
                                                       self.WABloodBarDeltaX,
                                                       self.WABloodBarDeltaY, self.GREEN, 0, 'small', self.ELSEKEY_1)

            # 格里恩血瓶(血条低于多少，必然触发)
            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.85, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.GREEN, 'small', 'i', 0.06, 2,
                                                  self.ELSEKEY_1, self.DEBUG_CLOSE)
            # ...
            # 格里恩图腾，极乐赦令(技能CD，不要多按)
            # self.pubAvgColorTiggerKeyCDMode(self.WA_SQUARE_ZFX_X3, self.WA_SQUARE_ZFX, self.WABloodBarDeltaX,
            #                                 self.WABloodBarDeltaY,
            #                                 self.WA_SQUARE_ZFX_AvgColor,
            #                                 self.RED, 'big', '5', 0.06, 2, self.ELSEKEY_1 ,self.DEBUG_CLOSE)
            if self.isLeftBottonZFXShow(self.WA_SQUARE_ZFX_X3, self.WA_SQUARE_ZFX, self.WABloodBarDeltaX,
                                        self.WABloodBarDeltaY, self.WA_SQUARE_ZFX_AvgColor) == False:
                # 保证血量低于某个，并且技能可用，才进行点击
                self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.80, self.WABloodBarY,
                                                      self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                      self.WABloodBarAvgColor, self.GREEN, 'small', '5', 0.06, 2,
                                                      self.ELSEKEY_1, self.DEBUG_CLOSE)
            else:
                # 群控一下
                self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.80, self.WABloodBarY,
                                                      self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                      self.WABloodBarAvgColor, self.GREEN, 'small', Key.f7, 0.06, 2,
                                                      self.ELSEKEY_1, self.DEBUG_CLOSE)

            # 打下碎片，紫色恢复学的紫球，适度消耗怒气（能量）
            self.pubAvgColorTiggerKeyBloodBarMode(self.WAEnergyBarX + self.WAEnergyBarWidth * 0.82,
                                                  self.WAEnergyBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.GREEN, 'big', Key.f8, 0.06, 6,
                                                  self.ELSEKEY_1, self.DEBUG_CLOSE)

    def CallBackHP80_70(self):
        while self.ui.stopLoop == False:
            # 饰品
            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.7, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.GREEN, 'small', 'o', 0.06, 2,
                                                  self.ELSEKEY_1, self.DEBUG_CLOSE)
            pass
    def CallBackHP70_60(self):
        while self.ui.stopLoop == False:

            # 饰品(血条低于多少，必然触发)
            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.6, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.GREEN, 'small', 'l', 0.06, 2,
                                                  self.ELSEKEY_1, self.DEBUG_CLOSE)
            sleep(0.3)
            pass
    def CallBackHP60_50(self):
        while self.ui.stopLoop == False:
            # 痛苦咒符（和减伤搭上关系）
            # self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.6, self.WABloodBarY,
            #                                       self.WABloodBarDeltaX, self.WABloodBarDeltaY,
            #                                       self.WABloodBarAvgColor, self.GREEN, 'small', 'p', 0.06, 2, self.ELSEKEY_1, self.DEBUG_CLOSE)

            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.55, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.GREEN, 'small', '[', 0.06, 2,
                                                  self.ELSEKEY_1, self.DEBUG_CLOSE)
            sleep(0.3)
            pass

    def CallBackHP50_40(self):
        while self.ui.stopLoop == False:
            # 术士治疗石(血条低于多少，必然触发)
            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.5, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.GREEN, 'small', 'n', 0.06, 2,
                                                  self.ELSEKEY_1, self.DEBUG_CLOSE)
            # 尖刺减伤(血条低于多少，必然触发)，危险，全部放出去
            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.5, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.RED, 'small', '8', 0.06, 2,
                                                  self.ELSEKEY_1, self.DEBUG_CLOSE)
            sleep(0.1)

    def CallBackHP40_30(self):
        while self.ui.stopLoop == False:
            # 黑暗（减伤）
            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.4, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.RED, 'small', Key.f5, 0.06, 2,
                                                  self.ELSEKEY_1, self.DEBUG_CLOSE)
            # 变恶魔(血条低于多少，必然触发)
            self.pubAvgColorTiggerKeyBloodBarMode(self.WABloodBarX + self.WABloodBarWidth * 0.35, self.WABloodBarY,
                                                  self.WABloodBarDeltaX, self.WABloodBarDeltaY,
                                                  self.WABloodBarAvgColor, self.RED, 'small', Key.f12, 0.06, 2,
                                                  self.ELSEKEY_1, self.DEBUG_CLOSE)
            sleep(0.2)
    def CallBackScheduler1(self):

        while self.ui.stopLoop == False:
            # # 裂魂，产生紫色的点.(技能CD，不要多按)
            # self.pubAvgColorTiggerKeyCDMode(self.WA_SQUARE_ZFX_X7, self.WA_SQUARE_ZFX, self.WABloodBarDeltaX,
            #                                 self.WABloodBarDeltaY,
            #                                 self.WA_SQUARE_ZFX_AvgColor,
            #                                 self.RED, 'big', '1', 0.06, 2,self.ELSEKEY_1 ,self.DEBUG_CLOSE)

            # 减伤分配机制，不要多个减伤重，平均分配
            # 烈火烙印(技能CD，不要多按)
            self.pubAvgColorTiggerKeyCDMode(self.WA_SQUARE_ZFX_X4, self.WA_SQUARE_ZFX, self.WABloodBarDeltaX,
                                            self.WABloodBarDeltaY,
                                            self.WA_SQUARE_ZFX_AvgColor,
                                            self.RED, 'big', '7', 0.06, 2, self.ELSEKEY_1 ,self.DEBUG_CLOSE)
            sleep(0.2)

            # 烈焰咒符(技能CD，不要多按)
            self.pubAvgColorTiggerKeyCDMode(self.WA_SQUARE_ZFX_X5, self.WA_SQUARE_ZFX, self.WABloodBarDeltaX,
                                            self.WABloodBarDeltaY,
                                            self.WA_SQUARE_ZFX_AvgColor,
                                            self.RED, 'big', '9', 0.06, 2, self.ELSEKEY_1 ,self.DEBUG_CLOSE)



    def CallBackScheduler2(self):
        # 并发执行
        while self.ui.stopLoop == False:

            # 群拉。投掷利刃(技能CD，不要多按)
            self.pubAvgColorTiggerKeyCDMode(self.WA_SQUARE_ZFX_X8, self.WA_SQUARE_ZFX, self.WABloodBarDeltaX,
                                            self.WABloodBarDeltaY,
                                            self.WA_SQUARE_ZFX_AvgColor,
                                            self.RED, 'big', '3', 0.06, 2, self.ELSEKEY_1 ,self.DEBUG_CLOSE)
            sleep(0.2)

            # 积累恶魔之怒，献祭光环(技能CD，不要多按)
            self.pubAvgColorTiggerKeyCDMode(self.WA_SQUARE_ZFX_X6, self.WA_SQUARE_ZFX, self.WABloodBarDeltaX,
                                            self.WABloodBarDeltaY,
                                            self.WA_SQUARE_ZFX_AvgColor,
                                            self.RED, 'big', '4', 0.06, 2, self.ELSEKEY_1 ,self.DEBUG_CLOSE)

    def CallBackScheduler4(self):
        # 并发执行
        while self.ui.stopLoop == False:
            # 裂魂，产生紫色的点.(技能CD，不要多按)
            # self.pubAvgColorTiggerKeyCDMode(193, self.WA_SQUARE_ZFX, self.WABloodBarDeltaX, self.WABloodBarDeltaY,
            #                                 self.WA_SQUARE_ZFX_AvgColor,
            #                                 self.RED, 'big', '1', 0.06, 2,self.ELSEKEY_1 ,self.DEBUG_CLOSE)
            # # 大喷(血条低于多少，必然触发)
            # self.pubAvgColorTiggerKeyBloodBarMode(548, self.WABloodBarY, self.WABloodBarDeltaX, self.WABloodBarDeltaY,
            #                                       self.WABloodBarAvgColor, self.RED, 'small', '2', 0.06, 1,self.ELSEKEY_1, self.DEBUG_CLOSE)
            # 大喷(CD不要多按)
            # pubAvgColorNoTrigger
            avgColor1 = self.pubAvgColorNoTrigger(self.WABloodBarX + self.WABloodBarWidth - 16, self.WABloodBarY - 4, 5,
                                                  5,
                                                  self.RED, 0)
            if avgColor1 < self.WABloodBarAvgColor:
                # 满血不碰
                self.pubAvgColorTiggerKeyCDMode(self.WA_SQUARE_ZFX_X1, self.WA_SQUARE_ZFX, self.WABloodBarDeltaX,
                                                self.WABloodBarDeltaY,
                                                self.WA_SQUARE_ZFX_AvgColor,
                                                self.RED, 'big', '2', 0.06, 2, self.ELSEKEY_1 ,self.DEBUG_CLOSE)

    def CallBackScheduler3(self):
        while self.ui.stopLoop == False:
            # 裂魂
            self.click(self.kb, '1', 2)
            sleep(0.1)

            # 邪能之刃
            self.click(self.kb, '\\', 3)
            sleep(0.1)

            self.click(self.kb, Key.f4, 2)

    def on_mouse_click_son_before_thread(self, x, y, button, pressed):
        # self.interruptAllByForce()
        pass
        return

    def x(self):
        for i in range(1, 4):
            self.click(self.kb, ']', 2)
            sleep(0.1)

        # 打断后的继续
        self.click(self.kb, 'a', 1)
        return

    def mouseUp(self, x, y):
        self.ui.stopLoop = True
        sleep(0.1)
        self.ui.stopLoop = False
        # 手工补尖刺
        log.debug('★鼠标向上滚，需要开始执行的内容★')
        for i in range(1, 4):
            self.click(self.kb, '8', 2)
            sleep(0.1)
        log.debug('★鼠标向上滚，需要over执行的内容★')

        return

    def mouseDown(self, x, y):
        self.ui.stopLoop = True
        sleep(0.1)
        self.ui.stopLoop = False
        # 手工开T的防护恶魔大招
        for i in range(1, 6):
            self.click(self.kb, 't', 2)
            sleep(0.1)
        return

    def w(self):
        for i in range(1, 6):
            self.click(self.kb, 't', 2)
            sleep(0.1)
        return

    def q(self):
        log.debug('★鼠标向上滚，需要开始执行的内容★')
        for i in range(1, 4):
            self.click(self.kb, '8', 2)
            sleep(0.1)
        log.debug('★鼠标向上滚，需要over执行的内容★')
        return


class DhDPS(Player):
    def a(self):
        while self.ui.stopLoop == False:
            self.click(self.kb, '1', 2)
            sleep(0.1)
            self.click(self.kb, '2', 2)
            sleep(0.1)
            self.click(self.kb, '3', 2)
            sleep(0.1)
            self.click(self.kb, '4', 2)
